package com.yyj.web.controller.manager;

import com.yyj.common.BaseResponse;
import com.yyj.constant.ReturnCode;
import com.yyj.constant.WebConstant;
import com.yyj.pojo.user.SessionInfo;
import com.yyj.service.WaterBillService;
import com.yyj.util.RspUtils;
import com.yyj.web.controller.BaseController;
import com.yyj.web.protocol.req.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(value = "管理员水费相关接口" , description="管理员水费相关接口")
@RestController
public class MWaterBillContoller extends BaseController {

    @Autowired
    WaterBillService waterBillService;

    @ApiOperation(value = "管理员查看已缴费水费记录详情")
    @RequestMapping(value = "/auth/managers/waterBills/detail/{roomNum}", method = RequestMethod.GET)
    public BaseResponse queryWaterBillDetail(@PathVariable String roomNum
    ){
        try{
            WaterBillQueryReq waterBillQueryReq = new WaterBillQueryReq();
            waterBillQueryReq.setRoomNum(roomNum);
            return RspUtils.success(waterBillService.queryWaterBillInfo(waterBillQueryReq));
        }catch(Exception e){
            logger.error("查看水费信息异常：{}" , e.getMessage() , e);
            return RspUtils.error(e.getMessage());
        }
    }

    @ApiOperation(value = "管理员审核业主水表提交记录")
    @RequestMapping(value = "/auth/managers/waterBills/audit", method = RequestMethod.POST)
    public BaseResponse queryWaterBillDetail(@RequestBody @Validated WaterBillAuditReq waterBillAuditReq
            , BindingResult result
    ){
        try{
            checkRequestParams(result);
            SessionInfo sessionInfo = (SessionInfo)session.getAttribute(WebConstant.SESSION_INFO);
            return RspUtils.success(waterBillService.auditWaterBill(waterBillAuditReq , sessionInfo));
        }catch(Exception e){
            logger.error("管理员审核业主水表提交记录异常：{}" , e.getMessage() , e);
            return RspUtils.error(e.getMessage());
        }
    }

    @ApiOperation(value = "管理员修改水表数据")
    @RequestMapping(value = "/auth/manager/waterBills/update" , method = RequestMethod.POST)
    public BaseResponse updateWaterBill(@RequestBody @Validated WaterBillManagerUpdateReq waterBillUpdateReq , BindingResult result){
        try{
            checkRequestParams(result);
            return RspUtils.success(waterBillService.managerUpdateWaterBill(waterBillUpdateReq));

        }catch(Exception e){
            logger.error("管理员修改水表数据异常：{}" , e.getMessage() , e);
            return RspUtils.error(ReturnCode.NORMAL_ERROR , e.getMessage());
        }
    }


}
